package com.dlc.felear.xiaoensale.activity;

import android.content.Intent;
import android.provider.Settings;
import android.text.InputType;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.dlc.felear.xiaoensale.R;
import com.dlc.felear.xiaoensale.constant.Constant;
import com.dlc.felear.xiaoensale.customView.ConfirmDialog;
import com.dlc.felear.xiaoensale.customView.SingleInputDialog;
import com.dlc.felear.xiaoensale.dao.LocalUserDao;
import com.dlc.felear.xiaoensale.deviceUtil.TopbarHelper;
import com.dlc.felear.xiaoensale.entity.LocalUser;
import com.dlc.felear.xiaoensale.helper.UpdateAppHelper;
import com.dlc.felear.xiaoensale.utils.UuidUtil;
import com.itdlc.android.library.base.BaseActivity;
import com.itdlc.android.library.utils.AppInfo;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 参数设置页面
 */
public class ParamerSettingActivity extends BaseActivity implements ConfirmDialog.ConfirmDialogCallback, SingleInputDialog.SingleDialogCallback {
    private TopbarHelper topbarHelper;
    private UpdateAppHelper updateAppHelper;
    @BindView(R.id.setting_tv_version)
    TextView tvVersion;
    private ConfirmDialog confirmDialog;
    private SingleInputDialog singleInputDialog;
    private LocalUserDao localUserDao;

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_paramer_setting;
    }

    @Override
    protected void initData() {
        topbarHelper = new TopbarHelper(this);
        topbarHelper.setcon(R.drawable.arrow_left);
        topbarHelper.setNavActivity(CcLauncherActivity.class);
        topbarHelper.setTitle("应用设置");
        updateAppHelper = new UpdateAppHelper(this);
        tvVersion.setText(" 版本升级   v" + AppInfo.getLocalVersionName(this));
        singleInputDialog = new SingleInputDialog(this, this);
        confirmDialog = new ConfirmDialog(this, this);
        localUserDao=new LocalUserDao(this);
    }

    @OnClick({R.id.s_ms, R.id.s_ds, R.id.s_setting, R.id.s_update, R.id.s_tl, R.id.s_piple, R.id.s_update_data, R.id.s_maintain})
    public void clickView(View view) {
        switch (view.getId()) {
            case R.id.s_ms:
                startActivity(new Intent(this, SfMotorDebugActivity.class));
                break;
            case R.id.s_maintain:
                baoyangyemian();
                break;
            case R.id.s_setting:
                startActivity(new Intent(Settings.ACTION_SETTINGS));
                break;
            case R.id.s_update:
                updateAppHelper.uploadApk();
                break;
            case R.id.s_tl:
                startActivity(new Intent(this, FlavourParamerSettingActivity.class));
                break;
            case R.id.s_piple:
                startActivity(new Intent(this, ManualDebugActivity.class));
                break;
            case R.id.s_update_data:
                startActivity(new Intent(this, LoadDataActivity.class));
                break;
            case R.id.s_ds:
                startActivity(new Intent(this, DeviceParamersSettingActivity.class));
                break;

        }
    }

    private void baoyangyemian() {
        singleInputDialog.showDialog(1);
        singleInputDialog.setTips("密码");
        singleInputDialog.setMiWen();
        singleInputDialog.setEtInputType(InputType.TYPE_CLASS_TEXT);
        singleInputDialog.setHintMsg("输入保养密码");
    }

    @Override
    public void selectResult(int value, int id) {
        if (value == 1) {
            switch (id) {
                case 1:
                    startActivity(new Intent(this, MotorPagerActivity.class));
                    break;
            }
        }
    }

    @Override
    public void SingleDialogInputResult(String value, int id) {
        switch (id) {
            case 1:
                LocalUser localUser=localUserDao.queryForId(UuidUtil.getUuidByName(Constant.USER_NAME));
                if (localUser!=null&&TextUtils.equals(value, localUser.getBypwd())) {
                    startActivity(new Intent(this, MotorPagerActivity.class));
                }else {
                    showShortToast("密码错误");
                }
                break;
        }
    }
}